/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import abstractmodel.InfoValue;
import java.text.DateFormat;

/**
 *
 * @author fightfxj
 */
public class CreditCardDetailInfo extends model.DetailInfo {
    Double canUseAmount;    //可用额度
    public static final String[] creditCardDetailInfoTitles = new String[]{"收支日期", "原因", "数额", "余额", "备注", "可用额度"};

    public CreditCardDetailInfo() {
        super();
        canUseAmount = new Double(0);
    }

    public double getCanUseAmount() {
        return canUseAmount;
    }
    
    @Override
    public String[] getTitles()  {
        return creditCardDetailInfoTitles;
    }
    
    @Override
    public InfoValue getValue(String title) {
        InfoValue iv = new InfoValue();
        iv.setType(this.getClass());
        if (title.equals("收支日期")) {
            iv.setObj(this.useTimeString);
            iv.setType(String.class);
        } 
        else if (title.equals("原因")) {
            iv.setObj(this.useReason);
            iv.setType(String.class);
        }
        else if (title.equals("数额")) {
            iv.setObj(this.moneyAmount);
            iv.setType(Double.class);
        }
        else if (title.equals("余额")) {
            iv.setObj(this.leftAmount);
            iv.setType(Double.class);
        }
        else if (title.equals("备注")) {
            iv.setObj(this.notes);
            iv.setType(String.class);
        }
        else if (title.equals("可用额度")) {
            iv.setObj(this.canUseAmount);
            iv.setType(Double.class);
        }
        else if (title.equalsIgnoreCase("id")) {
            iv.setObj(new Integer(this.id).toString());
            iv.setType(String.class);
        }   
        else if (title.equalsIgnoreCase("parentID")) {
            iv.setObj(new Integer(this.parentID).toString());
            iv.setType(String.class);
        } 
        ModelFactory.data.saveDetailInfo(this);
        return iv;
    }

    @Override
    public boolean setValue(String title, Object value) {
        if (title.equals("收支日期")) {
            try {
                this.useTime  = DateFormat.getDateInstance();
                this.useTime.getCalendar().setTime(configure.Global.sdf.parse(value.toString()));
                this.useTimeString = value.toString();
            } catch (Exception e) {
                System.out.println("Exception in set time of BankAccountInfo");
            }
        } 
        else if (title.equals("原因")) {
            this.useReason = value.toString();
        }
        else if (title.equals("数额")) {
            this.moneyAmount = new Double(value.toString()).doubleValue();
        }
        else if (title.equals("余额")) {
            this.leftAmount = new Double(value.toString()).doubleValue();
        }
        else if (title.equals("备注")) {
           this.notes = value.toString();
        }
        else if (title.equals("可用额度")) {
            this.canUseAmount = new Double(value.toString()).doubleValue();
        }
        return true;
    }    
    
    
    @Override
    public int getType() {
        return configure.Global.CREDITCARD_DETAIL_INFO_TYPE;
    }
}
